//--------------------------------------------------------------------------
// 
//  Copyright (c) Chili Software.  All rights reserved. 
// 
//  File: AddingQueryEventArgs.cs
//
//  Description: EventArgs used by the AddingQuery event.
// 
//--------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Chili.Opf3.Query;
using Chili.Opf3.Storages;

namespace Chili.Opf3.Caching
{
	/// <summary>
	/// EventArgs used by the AddingQuery event of the <see cref="SimpleCacheManager">SimpleCacheManager</see> Class.
	/// </summary>
	public sealed class AddingQueryEventArgs : EventArgs
	{
		private bool _cancel;
		private IQuery _query;
		private IStorage _storage;
		private DateTime _validUntil;
		private TimeSpan _executeTimeSpan;

		/// <summary>
		/// Creates a new instance of the <see cref="AddingQueryEventArgs">AddingQueryEventArgs Class</see>.
		/// </summary>
		/// <param name="validUntil">The time until the item is valid.</param>
		/// <param name="query">The query that is cached.</param>
		/// <param name="storage">The storage that the query is executed on.</param>
		/// <param name="executeTimeSpan">The timespan used to execute the query.</param>
		internal AddingQueryEventArgs(IQuery query, IStorage storage, DateTime validUntil, TimeSpan executeTimeSpan)
		{
			if (query == null)
				throw new ArgumentNullException("query");
			if (storage == null)
				throw new ArgumentNullException("storage");

			_query = query;
			_storage = storage;
			_validUntil = validUntil;
			_executeTimeSpan = executeTimeSpan;
		}

		/// <summary>
		/// Gets or sets whether to cancel the add to the cache for this query.
		/// </summary>
		public bool Cancel
		{
			get { return _cancel; }
			set { _cancel = value; }
		}

		/// <summary>
		/// Gets the query that is added to the cache.
		/// </summary>
		public IQuery Query
		{
			get { return _query; }
		}
		
		/// <summary>
		/// Gets the time span needed to execute the query.
		/// </summary>
		public TimeSpan ExecutionTimeSpan
		{
			get { return _executeTimeSpan; }
		}

		/// <summary>
		/// Gets the storage that the query is executed on.
		/// </summary>
		public IStorage Storage
		{
			get { return _storage; }
		}

		/// <summary>
		/// Gets or sets the date and time until the query is valid.
		/// </summary>
		public DateTime ValidUntil
		{
			get { return _validUntil; }
			set { _validUntil = value; }
		}
	}
}
